package login

import (
	"context"
	"github.com/cloudwego/hertz/pkg/common/hlog"
	"mall_admin_api/biz/dal"
	"mall_admin_api/biz/model"
	"mall_admin_api/biz/util"
)

type LoginService struct {
	dao *dal.InitDAO
}

func NewLoginService(bizID int64) *LoginService {
	return &LoginService{dao: dal.NewInitDAO(bizID)}
}

func (c *LoginService) Login(ctx context.Context, account, password string) (*model.Administrator, error) {
	pwd := util.Md5(password, true)
	info, err := c.dao.AdministratorDAO.Login(ctx, account, pwd)
	if err != nil {
		hlog.CtxErrorf(ctx, "login err: %v", err)
		return nil, err
	}

	return info, err
}
